<!DOCTYPE HTML>
<title>SVGTransformList, basics</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="resources/SVGTransformList-helper.js"></script>
<svg width="200" height="200">
    <circle cx="40" cy="40" r="40" fill="green" transform="scale(2, 2) translate(10 10)"/>
</svg>
<script>
test(function() {
  // This is a test of the simple SVGTransformList API parts.

  var svg = document.querySelector("svg");
  var circle1 = document.querySelector("circle");
  var transformList = circle1.transform.baseVal;

  // TODO(shanmuga.m) : // Split into several subtests.

  // Spec: The object referenced by animVal will always be distinct from the one referenced by baseVal, even when the attribute is not animated.
  assert_not_equals(circle1.transform.baseVal, circle1.transform.animVal);

  assert_equals(circle1.transform.baseVal.numberOfItems, 2);
  assert_equals(circle1.transform.animVal.numberOfItems, 2);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");

  // Test uncommon arguments for initialize().
  assert_throws_js(TypeError, function() { transformList.initialize(30); });
  assert_throws_js(TypeError, function() { transformList.initialize('aString'); });
  assert_throws_js(TypeError, function() { transformList.initialize(circle1); });
  assert_throws_js(TypeError, function() { transformList.initialize(null); });

  // Test uncommon arguments for getItem().
  assert_throws_dom("IndexSizeError", function() { transformList.getItem(30); });
  assert_equals(transformList.getItem('aString').toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(circle1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(null).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");

  // Test uncommon arguments for insertItemBefore().
  assert_throws_js(TypeError, function() { transformList.insertItemBefore(30); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore('aString'); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore(circle1); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore(null); });

  assert_equals(transformList.insertItemBefore(transformList.getItem(1), 'aString').toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.numberOfItems, 3);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(circle1.getAttribute('transform'), "translate(10 10) scale(2 2) translate(10 10)");

  assert_equals(transformList.insertItemBefore(transformList.getItem(1), circle1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10) scale(2 2) translate(10 10)");

  assert_equals(transformList.insertItemBefore(transformList.getItem(1), null).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.numberOfItems, 5);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(4).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(circle1.getAttribute('transform'), "translate(10 10) scale(2 2) translate(10 10) scale(2 2) translate(10 10)");

  assert_equals(transformList.insertItemBefore(transformList.getItem(1), 0).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 6);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(4).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(5).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10) scale(2 2) translate(10 10) scale(2 2) translate(10 10)");

  assert_throws_js(TypeError, function() { transformList.insertItemBefore(30, 0); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore('aString', 0); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore(circle1, 0); });
  assert_throws_js(TypeError, function() { transformList.insertItemBefore(null, 0); });

  // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle1.
  circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skewX(45)');
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) translate(10 10) skewX(45)");

  // Test uncommon arguments for replaceItem().
  assert_throws_js(TypeError, function() { transformList.replaceItem(30); });
  assert_throws_js(TypeError, function() { transformList.replaceItem('aString'); });
  assert_throws_js(TypeError, function() { transformList.replaceItem(circle1); });
  assert_throws_js(TypeError, function() { transformList.replaceItem(null); });
  assert_throws_js(TypeError, function() { transformList.replaceItem(30, 0); });
  assert_throws_js(TypeError, function() { transformList.replaceItem('aString', 0); });
  assert_throws_js(TypeError, function() { transformList.replaceItem(circle1, 0); });
  assert_throws_js(TypeError, function() { transformList.replaceItem(null, 0); });

  // Test uncommon values for indexed setter.
  assert_throws_js(TypeError, function() { transformList[0] = 30; });
  assert_throws_js(TypeError, function() { transformList[0] = 'aString'; });
  assert_throws_js(TypeError, function() { transformList[0] = circle1; });
  assert_throws_js(TypeError, function() { transformList[0] = null; });

  assert_equals(transformList.replaceItem(transformList.getItem(3), 0).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "skewX(45) scale(2 2) translate(10 10) skewX(45)");

  // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle1.
  circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skewX(45)');
  assert_equals(transformList.replaceItem(transformList.getItem(0), 'aString').toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) translate(10 10) skewX(45)");

  assert_equals(transformList.replaceItem(transformList.getItem(0), circle1).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(3).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) translate(10 10) skewX(45)");

  assert_equals(transformList.replaceItem(transformList.getItem(0), null).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 4);
  assert_equals(circle1.getAttribute('transform'), "rotate(90) scale(2 2) translate(10 10) skewX(45)");

  // Set transform='rotate(90) scale(2 2) translate(10 10) skewX(45)' for circle1.
  circle1.setAttribute('transform', 'rotate(90) scale(2 2) translate(10 10) skewX(45)');

  // Test uncommon arguments for removeItem().
  assert_throws_dom("IndexSizeError", function() { transformList.removeItem(30); });

  assert_equals(transformList.removeItem(0).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.0 1.0 -1.0 0.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 3);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(2).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "scale(2 2) translate(10 10) skewX(45)");

  assert_equals(transformList.removeItem('aString').toString(), "type=SVG_TRANSFORM_SCALE matrix=[2.0 0.0 0.0 2.0 0.0 0.0]");
  assert_equals(transformList.numberOfItems, 2);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.getItem(1).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "translate(10 10) skewX(45)");

  assert_equals(transformList.removeItem(circle1).toString(), "type=SVG_TRANSFORM_TRANSLATE matrix=[1.0 0.0 0.0 1.0 10.0 10.0]");
  assert_equals(transformList.numberOfItems, 1);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_SKEWX matrix=[1.0 0.0 1.0 1.0 0.0 0.0]");
  assert_equals(circle1.getAttribute('transform'), "skewX(45)");

  // Test uncommon arguments for appendItem().
  assert_throws_js(TypeError, function() { transformList.appendItem(30); });
  assert_throws_js(TypeError, function() { transformList.appendItem('aString'); });
  assert_throws_js(TypeError, function() { transformList.appendItem(circle1); });
  assert_throws_js(TypeError, function() { transformList.appendItem(null); });

  // Testing animVal clear throws.
  assert_throws_dom("NoModificationAllowedError", function() { circle1.transform.animVal.clear(); });
  transformList.clear();

  // Creating new SVGTransform, with 45 deg rotation about x=50, y=100 and append it to the transform list.
  var transform = svg.createSVGTransform();
  assert_equals(transform.toString(), "type=SVG_TRANSFORM_MATRIX matrix=[1.0 0.0 0.0 1.0 0.0 0.0]");
  transform.setRotate(45, 50, 100);

  assert_equals(transformList.appendItem(transform).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.7 0.7 -0.7 0.7 85.4 -6.1]");
  assert_equals(transformList.numberOfItems, 1);
  assert_equals(transformList.getItem(0).toString(), "type=SVG_TRANSFORM_ROTATE matrix=[0.7 0.7 -0.7 0.7 85.4 -6.1]");
  assert_equals(circle1.getAttribute('transform'), "rotate(45 50 100)");
});
</script>